//
//  LRBaseTableViewController.swift
//  LRWeibo
//
//  Created by admin on 15/9/21.
//  Copyright © 2015年 懒人. All rights reserved.
//

import UIKit

class LRBaseTableViewController: UITableViewController {

    var isLogin = UserAccountViewModel.sharedUserAccount.isLogin
    let visitorView = LRVisitorView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if isLogin
        {
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "退出", style: .Plain, target: self, action: "clickExit")
        }
        else
        {
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "clickLogin")
        }
    }

    override func loadView() {
        
        // 判断是否登录显示
        isLogin ? super.loadView() : setVisitorView()

    }
    
    private func setVisitorView()
    {
        view = visitorView
        
        // 注册按钮事件
        visitorView.registerButton.addTarget(self, action: "clickRegister", forControlEvents: .TouchUpInside)
        visitorView.loginButton.addTarget(self, action: "clickLogin", forControlEvents: .TouchUpInside)
    }
    
    // MARK: - 按钮点击事件
    @objc private func clickRegister()
    {
        
    }
    
    @objc private func clickLogin()
    {
        let oauth:LROAuthViewController = LROAuthViewController()
        let nav = UINavigationController(rootViewController: oauth)
        self.navigationController?.presentViewController(nav, animated: true, completion: nil)
    }

    @objc private func clickExit()
    {
//        do{
//            _ = try NSFileManager.defaultManager().removeItemAtPath(UserAccountViewModel.sharedUserAccount.savePath!)
//        }catch
//        {
//            print(error)
//        }
    }
}
